package com.example.demo.mapper;

import com.example.demo.pojo.Back;
import com.example.demo.pojo.Borrow;
import com.example.demo.pojo.BorrowCountP0;
import com.example.demo.pojo.request.BorrowRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface BorrowMapper {
    //查询全部
    List<Borrow> list();

    //分页
    List<Borrow> page(BorrowRequest request);

    //还书分页
    List<Back> pageBack(BorrowRequest request);
    //添加
    @Insert("insert into library.borrow (book_name,book_no,user_idcard,user_name,user_phone,create_time,score,days,return_date) values" +
            " (#{bookName}, #{bookNo}, #{userIdcard}, #{userName}, #{userPhone},#{createTime},#{score},#{days},#{returnDate})")
    void save(Borrow Borrow);

    //添加还书数据
    @Insert("insert into library.back (book_name,book_no,user_idcard,user_name,user_phone,create_time,score,days,return_date,real_date,status) values" +
            " (#{bookName}, #{bookNo}, #{userIdcard}, #{userName}, #{userPhone},#{createTime},#{score},#{days},#{returnDate},#{realDate},#{status})")
    void saveBack(Back back);

    //查找
    @Select("select * from library.borrow where id=#{id}")
    Borrow getUser(Integer id);

    //更新
    @Update("update library.borrow set status=#{status} where id=#{id}")
    void getUserByID(Borrow Borrow);

    //删除
    @Delete("delete from library.borrow where id=#{id}")
    void delete(Integer id);

    //删除还书数据
    @Delete("delete from library.back where id=#{id}")
    void deleteBack(Integer id);

    List<BorrowCountP0> getCountByTimeRange(@Param("timeRange") String timeRange,@Param("type") int type);
}
